package com.qianfeng.libra.cowshop.app.activities.home;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import com.qianfeng.libra.cowshop.app.R;
import com.qianfeng.libra.cowshop.app.configuration.Constants;

public class StartActivity extends FragmentActivity implements Runnable{

    private SharedPreferences sharedPreferences;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_start);
        //通过SharePreference进行判断是否显示过教程页
        sharedPreferences = getSharedPreferences(Constants.SP_APP_DATA, MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putBoolean("isLogin",false);
        edit.putBoolean("isCartEmpty",true);
        edit.commit();
        Thread thread = new Thread(this);
        thread.start();


    }

    @Override
    public void run() {
        try {
            Thread.sleep(2000);
            showNext();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    private void showNext() {


        //是否启动过教程界面
        boolean shownTutorial = sharedPreferences.getBoolean(Constants.SP_KEY_TUTORIAL_SHOWN, false);
        if (shownTutorial) {
            //显示过教程界面，启动主界面
            startActivity(new Intent(this, MainActivity.class));
        } else {
            //没有显示过教程界面，启动教程页面
            startActivity(new Intent(this, TutorialActivity.class));
        }
        finish();
    }
}
